package com.cpic.rxjava;

import android.util.Log;

public class MapObserver<T,R> implements Observer<T> {
    Function<T,R> function;
    final Observer<R> observer;

    public MapObserver(Function<T, R> function, Observer<R> observer) {
        this.function = function;
        this.observer = observer;
        Log.e("MapObserver",this.toString());
    }

    @Override
    public void onNext(T t) {
       R r=  function.apply(t);
        Log.e("MapObserver", this.toString()+"   "+"onNext" );
        observer.onNext(r);
    }

    @Override
    public void onError(Throwable throwable) {
        observer.onError(throwable);
    }

    @Override
    public void onSubcribe() {
        Log.e("MapObserver", this.toString()+"   "+"onSubcribe" );

        observer.onSubcribe();
    }

    @Override
    public void onComplete() {
        Log.e("MapObserver", this.toString()+"   "+"onComplete" );

        observer.onComplete();
    }
}
